package com.mitgroup.dmrvs.view;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONArray;
import com.mitgroup.dmrvs.R;
import com.mitgroup.dmrvs.utils.AppManager;
import com.mitgroup.dmrvs.utils.Utils;
import com.mitgroup.dmrvs.webservice.WSClient;

import org.json.JSONObject;
import org.json.JSONTokener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.trinea.android.common.util.PreferencesUtils;

public class UpdateWorkOrderActivity extends AppCompatActivity {
    private static final int MSG_SUBMIT_MAINTENANCE_ITEM = 1;
    private static final String BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_FAIL = "submit_maintenance_item_fail";
    private static final String BUNDLE_LOCAL_ERROR = "local_error";
    private static final String BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_SUCCESS = "submit_maintenance_item_success";
    private static final String BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_CHOOSE = "submit_maintenance_item_choose";
    private static final int MSG_GET_MAINTENANCE_ITEM = 2;
    private static final String BUNDLE_MSG_GET_MAINTENANCE_ITEM = "get_maintenance_item";
    private static final String BUNDLE_MSG_GET_MAINTENANCE_ITEM_SUCCESS = "get_maintenance_item_success";
    private static final String BUNDLE_MSG_GET_MAINTENANCE_ITEM_FAIL = "get_maintenance_item_fail";
    private static final int MSG_GET_WORK_ORDER_ITEM = 3;
    private static final String BUNDLE_MSG_GET_WORK_ORDER_ITEM = "get_work_order_item";
    private static final String BUNDLE_MSG_GET_WORK_ORDER_ITEM_SUCCESS = "get_work_order_item_success";
    private static final String BUNDLE_MSG_GET_WORK_ORDER_ITEM_FAIL = "get_work_order_item_fail";
    private Intent intent;
    private ProgressDialog progressDialog;
    /**
     * handler对象
     */
    private Handler handler;
    String userName;
    String carInfoId;
    String userId;
    @BindView(R.id.btn_back)
    public Button btnBack;

    @OnClick(R.id.btn_back)
    public void onBack(View view) {
        this.finish();
    }

    @BindView(R.id.tv_user_name)
    public TextView tvUserName;
    @BindView(R.id.btn_nav01)
    public Button btnReceiveCar;

    @OnClick(R.id.btn_nav01)
    public void onReceiveCar(View view) {
        intent = new Intent(UpdateWorkOrderActivity.this,
                ReceiveCarActivity.class);
        startActivity(intent);
    }

    @BindView(R.id.btn_nav02)
    public Button btnDiagnose;

    @OnClick(R.id.btn_nav02)
    public void onDiagnose(View view) {
        intent = new Intent(UpdateWorkOrderActivity.this,
                CarDiagnoseActivity.class);
        startActivity(intent);
    }

    @BindView(R.id.btn_nav03)
    public Button btnSettings;

    @OnClick(R.id.btn_nav03)
    public void onSettings(View view) {
        intent = new Intent(UpdateWorkOrderActivity.this,
                SettingsActivity.class);
        startActivity(intent);
    }

    @BindView(R.id.iv_quit)
    public Button quit;

    @OnClick(R.id.iv_quit)
    public void onQuit(View view) {
        Utils.Exit(this);
    }

    @BindView(R.id.tv_maintenance_item_id_1)
    public TextView tvMaintenanceItemId1;
    @BindView(R.id.tv_item_name_1)
    public TextView tvItemName1;
    @BindView(R.id.tv_man_hour_fee_1)
    public TextView tvManHourFee1;
    @BindView(R.id.tv_spare_part_name_1)
    public TextView tvSpairPartName1;
    @BindView(R.id.tv_spare_part_number_1)
    public TextView tvSpairPartNumber1;
    @BindView(R.id.tv_price_1)
    public TextView tvPrice1;

    @BindView(R.id.tv_maintenance_item_id_2)
    public TextView tvMaintenanceItemId2;
    @BindView(R.id.tv_item_name_2)
    public TextView tvItemName2;
    @BindView(R.id.tv_man_hour_fee_2)
    public TextView tvManHourFee2;
    @BindView(R.id.tv_spare_part_name_2)
    public TextView tvSpairPartName2;
    @BindView(R.id.tv_spare_part_number_2)
    public TextView tvSpairPartNumber2;
    @BindView(R.id.tv_price_2)
    public TextView tvPrice2;

    @BindView(R.id.tv_maintenance_item_id_3)
    public TextView tvMaintenanceItemId3;
    @BindView(R.id.tv_item_name_3)
    public TextView tvItemName3;
    @BindView(R.id.tv_man_hour_fee_3)
    public TextView tvManHourFee3;
    @BindView(R.id.tv_spare_part_name_3)
    public TextView tvSpairPartName3;
    @BindView(R.id.tv_spare_part_number_3)
    public TextView tvSpairPartNumber3;
    @BindView(R.id.tv_price_3)
    public TextView tvPrice3;

    @BindView(R.id.tv_maintenance_item_id_4)
    public TextView tvMaintenanceItemId4;
    @BindView(R.id.tv_item_name_4)
    public TextView tvItemName4;
    @BindView(R.id.tv_man_hour_fee_4)
    public TextView tvManHourFee4;
    @BindView(R.id.tv_spare_part_name_4)
    public TextView tvSpairPartName4;
    @BindView(R.id.tv_spare_part_number_4)
    public TextView tvSpairPartNumber4;
    @BindView(R.id.tv_price_4)
    public TextView tvPrice4;

    @BindView(R.id.tv_maintenance_item_id_5)
    public TextView tvMaintenanceItemId5;
    @BindView(R.id.tv_item_name_5)
    public TextView tvItemName5;
    @BindView(R.id.tv_man_hour_fee_5)
    public TextView tvManHourFee5;
    @BindView(R.id.tv_spare_part_name_5)
    public TextView tvSpairPartName5;
    @BindView(R.id.tv_spare_part_number_5)
    public TextView tvSpairPartNumber5;
    @BindView(R.id.tv_price_5)
    public TextView tvPrice5;

    @BindView(R.id.tv_maintenance_item_id_6)
    public TextView tvMaintenanceItemId6;
    @BindView(R.id.tv_item_name_6)
    public TextView tvItemName6;
    @BindView(R.id.tv_man_hour_fee_6)
    public TextView tvManHourFee6;
    @BindView(R.id.tv_spare_part_name_6)
    public TextView tvSpairPartName6;
    @BindView(R.id.tv_spare_part_number_6)
    public TextView tvSpairPartNumber6;
    @BindView(R.id.tv_price_6)
    public TextView tvPrice6;

    @BindView(R.id.tv_maintenance_item_id_7)
    public TextView tvMaintenanceItemId7;
    @BindView(R.id.tv_item_name_7)
    public TextView tvItemName7;
    @BindView(R.id.tv_man_hour_fee_7)
    public TextView tvManHourFee7;
    @BindView(R.id.tv_spare_part_name_7)
    public TextView tvSpairPartName7;
    @BindView(R.id.tv_spare_part_number_7)
    public TextView tvSpairPartNumber7;
    @BindView(R.id.tv_price_7)
    public TextView tvPrice7;

    @BindView(R.id.tv_maintenance_item_id_8)
    public TextView tvMaintenanceItemId8;
    @BindView(R.id.tv_item_name_8)
    public TextView tvItemName8;
    @BindView(R.id.tv_man_hour_fee_8)
    public TextView tvManHourFee8;
    @BindView(R.id.tv_spare_part_name_8)
    public TextView tvSpairPartName8;
    @BindView(R.id.tv_spare_part_number_8)
    public TextView tvSpairPartNumber8;
    @BindView(R.id.tv_price_8)
    public TextView tvPrice8;

    @BindView(R.id.tv_maintenance_item_id_9)
    public TextView tvMaintenanceItemId9;
    @BindView(R.id.tv_item_name_9)
    public TextView tvItemName9;
    @BindView(R.id.tv_man_hour_fee_9)
    public TextView tvManHourFee9;
    @BindView(R.id.tv_spare_part_name_9)
    public TextView tvSpairPartName9;
    @BindView(R.id.tv_spare_part_number_9)
    public TextView tvSpairPartNumber9;
    @BindView(R.id.tv_price_9)
    public TextView tvPrice9;

    @BindView(R.id.tv_maintenance_item_id_10)
    public TextView tvMaintenanceItemId10;
    @BindView(R.id.tv_item_name_10)
    public TextView tvItemName10;
    @BindView(R.id.tv_man_hour_fee_10)
    public TextView tvManHourFee10;
    @BindView(R.id.tv_spare_part_name_10)
    public TextView tvSpairPartName10;
    @BindView(R.id.tv_spare_part_number_10)
    public TextView tvSpairPartNumber10;
    @BindView(R.id.tv_price_10)
    public TextView tvPrice10;

    @BindView(R.id.tv_maintenance_item_id_11)
    public TextView tvMaintenanceItemId11;
    @BindView(R.id.tv_item_name_11)
    public TextView tvItemName11;
    @BindView(R.id.tv_man_hour_fee_11)
    public TextView tvManHourFee11;
    @BindView(R.id.tv_spare_part_name_11)
    public TextView tvSpairPartName11;
    @BindView(R.id.tv_spare_part_number_11)
    public TextView tvSpairPartNumber11;
    @BindView(R.id.tv_price_11)
    public TextView tvPrice11;

    @BindView(R.id.tv_maintenance_item_id_12)
    public TextView tvMaintenanceItemId12;
    @BindView(R.id.tv_item_name_12)
    public TextView tvItemName12;
    @BindView(R.id.tv_man_hour_fee_12)
    public TextView tvManHourFee12;
    @BindView(R.id.tv_spare_part_name_12)
    public TextView tvSpairPartName12;
    @BindView(R.id.tv_spare_part_number_12)
    public TextView tvSpairPartNumber12;
    @BindView(R.id.tv_price_12)
    public TextView tvPrice12;

    @BindView(R.id.tv_maintenance_item_id_13)
    public TextView tvMaintenanceItemId13;
    @BindView(R.id.tv_item_name_13)
    public TextView tvItemName13;
    @BindView(R.id.tv_man_hour_fee_13)
    public TextView tvManHourFee13;
    @BindView(R.id.tv_spare_part_name_13)
    public TextView tvSpairPartName13;
    @BindView(R.id.tv_spare_part_number_13)
    public TextView tvSpairPartNumber13;
    @BindView(R.id.tv_price_13)
    public TextView tvPrice13;

    @BindView(R.id.tv_maintenance_item_id_14)
    public TextView tvMaintenanceItemId14;
    @BindView(R.id.tv_item_name_14)
    public TextView tvItemName14;
    @BindView(R.id.tv_man_hour_fee_14)
    public TextView tvManHourFee14;
    @BindView(R.id.tv_spare_part_name_14)
    public TextView tvSpairPartName14;
    @BindView(R.id.tv_spare_part_number_14)
    public TextView tvSpairPartNumber14;
    @BindView(R.id.tv_price_14)
    public TextView tvPrice14;

    @BindView(R.id.tv_maintenance_item_id_15)
    public TextView tvMaintenanceItemId15;
    @BindView(R.id.tv_item_name_15)
    public TextView tvItemName15;
    @BindView(R.id.tv_man_hour_fee_15)
    public TextView tvManHourFee15;
    @BindView(R.id.tv_spare_part_name_15)
    public TextView tvSpairPartName15;
    @BindView(R.id.tv_spare_part_number_15)
    public TextView tvSpairPartNumber15;
    @BindView(R.id.tv_price_15)
    public TextView tvPrice15;

    @BindView(R.id.tv_maintenance_item_id_16)
    public TextView tvMaintenanceItemId16;
    @BindView(R.id.tv_item_name_16)
    public TextView tvItemName16;
    @BindView(R.id.tv_man_hour_fee_16)
    public TextView tvManHourFee16;
    @BindView(R.id.tv_spare_part_name_16)
    public TextView tvSpairPartName16;
    @BindView(R.id.tv_spare_part_number_16)
    public TextView tvSpairPartNumber16;
    @BindView(R.id.tv_price_16)
    public TextView tvPrice16;
    @OnClick({R.id.tv_spare_part_name_1,R.id.tv_spare_part_name_2,R.id.tv_spare_part_name_3,R.id.tv_spare_part_name_4,R.id.tv_spare_part_name_5,R.id.tv_spare_part_name_6,R.id.tv_spare_part_name_7,R.id.tv_spare_part_name_8,R.id.tv_spare_part_name_9,R.id.tv_spare_part_name_10,R.id.tv_spare_part_name_11,R.id.tv_spare_part_name_12,R.id.tv_spare_part_name_13,R.id.tv_spare_part_name_14,R.id.tv_spare_part_name_15,R.id.tv_spare_part_name_16})
    public void onDispSparePart(TextView  view) {
        String spareParts="";
        switch (view.getId()) {
            case R.id.tv_spare_part_name_1:
                spareParts=tvSpairPartName1.getText()+",";
                break;
            case R.id.tv_spare_part_name_2:
                spareParts=tvSpairPartName2.getText()+",";
                break;
            case R.id.tv_spare_part_name_3:
                spareParts=tvSpairPartName3.getText()+",";
                break;
            case R.id.tv_spare_part_name_4:
                spareParts=tvSpairPartName4.getText()+",";
                break;
            case R.id.tv_spare_part_name_5:
                spareParts=tvSpairPartName5.getText()+",";
                break;
            case R.id.tv_spare_part_name_6:
                spareParts=tvSpairPartName6.getText()+",";
                break;
            case R.id.tv_spare_part_name_7:
                spareParts=tvSpairPartName7.getText()+",";
                break;
            case R.id.tv_spare_part_name_8:
                spareParts=tvSpairPartName8.getText()+",";
                break;
            case R.id.tv_spare_part_name_9:
                spareParts=tvSpairPartName9.getText()+",";
                break;
            case R.id.tv_spare_part_name_10:
                spareParts=tvSpairPartName10.getText()+",";
                break;
            case R.id.tv_spare_part_name_11:
                spareParts=tvSpairPartName11.getText()+",";
                break;
            case R.id.tv_spare_part_name_12:
                spareParts=tvSpairPartName12.getText()+",";
                break;
            case R.id.tv_spare_part_name_13:
                spareParts=tvSpairPartName13.getText()+",";
                break;
            case R.id.tv_spare_part_name_14:
                spareParts=tvSpairPartName14.getText()+",";
                break;
            case R.id.tv_spare_part_name_15:
                spareParts=tvSpairPartName15.getText()+",";
                break;
            case R.id.tv_spare_part_name_16:
                spareParts=tvSpairPartName16.getText()+",";
                break;
            default:
                break;
        }
//        intent = new Intent(UpdateWorkOrderActivity.this,
//                RecommendProductsActivity.class);
//        intent.putExtra("product", spareParts.toLowerCase());
//        startActivity(intent);
        new DispImageDialog(UpdateWorkOrderActivity.this,spareParts.toLowerCase()).show();
    }
    @BindView(R.id.cb_1)
    public CheckBox cb1;
    @BindView(R.id.cb_2)
    public CheckBox cb2;
    @BindView(R.id.cb_3)
    public CheckBox cb3;
    @BindView(R.id.cb_4)
    public CheckBox cb4;
    @BindView(R.id.cb_5)
    public CheckBox cb5;
    @BindView(R.id.cb_6)
    public CheckBox cb6;
    @BindView(R.id.cb_7)
    public CheckBox cb7;
    @BindView(R.id.cb_8)
    public CheckBox cb8;
    @BindView(R.id.cb_9)
    public CheckBox cb9;
    @BindView(R.id.cb_10)
    public CheckBox cb10;
    @BindView(R.id.cb_11)
    public CheckBox cb11;
    @BindView(R.id.cb_12)
    public CheckBox cb12;
    @BindView(R.id.cb_13)
    public CheckBox cb13;
    @BindView(R.id.cb_14)
    public CheckBox cb14;
    @BindView(R.id.cb_15)
    public CheckBox cb15;
    @BindView(R.id.cb_16)
    public CheckBox cb16;

    @BindView(R.id.btn_submit_maintenance_item)
    public Button btnSubmitMaintenanceItem;

    @OnClick(R.id.btn_submit_maintenance_item)
    public void onSubmitMaintenanceItem(View view) {
        String maintenanceItemId = "";
        String itemName = "";
        String manHourFee = "";
        String sparePartName = "";
        String sparePartNumber = "";
        String price = "";
        int manHourFeeTotal = 0;
        int materialFeeTotal = 0;
        StringBuilder sb = new StringBuilder();
        sb.append("{\"maintenanceItems\":");
        sb.append("[");
        if (cb1.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId1.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName1.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee1.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName1.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber1.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice1.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb2.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId2.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName2.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee2.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName2.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber2.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice2.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb3.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId3.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName3.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee3.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName3.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber3.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice3.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb4.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId4.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName4.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee4.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal=manHourFeeTotal+Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName4.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber4.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice4.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb5.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId5.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName5.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee5.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName5.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber5.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice5.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb6.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId6.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName6.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee6.getText().toString();
            sb.append("\"manHourFee\":");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sb.append("\"" + manHourFee + "\",");
            sparePartName = tvSpairPartName6.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber6.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice6.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb7.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId7.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName7.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee7.getText().toString();
            sb.append("\"manHourFee\":");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sb.append("\"" + manHourFee + "\",");
            sparePartName = tvSpairPartName7.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber7.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice7.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb8.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId8.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName8.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee8.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName8.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber8.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice8.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb9.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId9.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName9.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee9.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName9.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber9.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice9.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb10.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId10.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName10.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee10.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName10.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber10.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice10.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb11.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId11.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName11.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee11.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName11.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber11.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice11.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb12.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId12.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName12.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee12.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName12.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber12.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice12.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb13.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId13.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName13.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee13.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName13.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber13.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice13.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb14.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId14.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName14.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee14.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName14.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber14.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice14.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb15.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId15.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName15.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee15.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName15.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber15.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice15.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");
        }
        if (cb16.isChecked()) {
            sb.append("{");
            maintenanceItemId = tvMaintenanceItemId16.getText().toString();
            sb.append("\"maintenanceItemId\":");
            sb.append("\"" + maintenanceItemId + "\",");
            itemName = tvItemName16.getText().toString();
            sb.append("\"itemName\":");
            sb.append("\"" + itemName + "\",");
            manHourFee = tvManHourFee16.getText().toString();
            sb.append("\"manHourFee\":");
            sb.append("\"" + manHourFee + "\",");
            manHourFeeTotal = manHourFeeTotal + Integer.parseInt(manHourFee);
            sparePartName = tvSpairPartName16.getText().toString();
            sb.append("\"sparePartName\":");
            sb.append("\"" + sparePartName + "\",");
            sparePartNumber = tvSpairPartNumber16.getText().toString();
            sb.append("\"sparePartNumber\":");
            sb.append("\"" + sparePartNumber + "\",");
            price = tvPrice16.getText().toString();
            sb.append("\"price\":");
            sb.append("\"" + price + "\"");
            materialFeeTotal = materialFeeTotal + Integer.parseInt(price);
            sb.append("},");

        }
        sb.append("{\"maintenanceItemId\":\"\"").append(",\"manHourFee\":\"\"").append(",\"sparePartName\":\"\"").append(",\"sparePartNumber\":\"\"").append(",\"price\":\"\"}");
        sb.append("],");
        sb.append("\"workOrderId\":").append("\"" + workOrderId + "\",");
        sb.append("\"userId\":").append("\"" + userId + "\",");
        sb.append("\"repairShopId\":").append("\"" + repairShopId + "\",");
        sb.append("\"carInfoId\":").append("\"" + carInfoId + "\",");
        sb.append("\"manHourFeeTotal\":").append("\"" + manHourFeeTotal + "\",");
        sb.append("\"materialFeeTotal\":").append("\"" + materialFeeTotal + "\",");
        sb.append("\"operator\":").append("\"" + userName + "\"");
        sb.append("}");
        submitMaintenanceItem(sb.toString());

    }

    private String repairShopId;
    public String workOrderId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_work_order);
        ButterKnife.bind(this);
        initView();

    }


    private void initView() {
        AppManager.getAppManager().addActivity(this);
        userId = PreferencesUtils.getString(UpdateWorkOrderActivity.this, "userId");
        userName = PreferencesUtils.getString(UpdateWorkOrderActivity.this, "userName");
        carInfoId = getIntent().getStringExtra("carInfoId");
        tvUserName.setText(userName);
        repairShopId = PreferencesUtils.getString(UpdateWorkOrderActivity.this, "repairShopId");
        getMaintenanceItem(repairShopId);


    }

    private Handler myHandler = new Handler() {
        String key = "";

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            String key = "";
            switch (msg.what) {
                case MSG_GET_WORK_ORDER_ITEM:
                    key = msg.getData().keySet().iterator().next();
                    if (BUNDLE_MSG_GET_WORK_ORDER_ITEM_FAIL.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, msg.getData().getString(BUNDLE_MSG_GET_WORK_ORDER_ITEM_FAIL), Toast.LENGTH_SHORT).show();
                    } else if (BUNDLE_LOCAL_ERROR.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, "服务器连接失败！", Toast.LENGTH_SHORT).show();

                    } else if (BUNDLE_MSG_GET_WORK_ORDER_ITEM_SUCCESS.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        String content = msg.getData().getString(BUNDLE_MSG_GET_WORK_ORDER_ITEM_SUCCESS);
                        if (!"".equals(content)) {
                            try {
                                com.alibaba.fastjson.JSONObject obj = com.alibaba.fastjson.JSONObject.parseObject(content);
                                JSONArray contentArray = obj.getJSONArray("content");
                                String itemId = "";

                                for (int i = 0; i < contentArray.size(); i++) {
                                    // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                                    com.alibaba.fastjson.JSONObject job = contentArray.getJSONObject(i);
                                    itemId = job.getString("itemId");
                                    workOrderId = job.getString("workOrderId");
                                    if(itemId.equals(tvMaintenanceItemId1.getText().toString()))
                                    {
                                       cb1.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId2.getText().toString()))
                                    {
                                        cb2.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId3.getText().toString()))
                                    {
                                        cb3.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId4.getText().toString()))
                                    {
                                        cb4.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId5.getText().toString()))
                                    {
                                        cb5.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId6.getText().toString()))
                                    {
                                        cb6.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId7.getText().toString()))
                                    {
                                        cb7.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId8.getText().toString()))
                                    {
                                        cb8.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId9.getText().toString()))
                                    {
                                        cb9.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId10.getText().toString()))
                                    {
                                        cb10.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId11.getText().toString()))
                                    {
                                        cb11.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId12.getText().toString()))
                                    {
                                        cb12.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId13.getText().toString()))
                                    {
                                        cb13.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId14.getText().toString()))
                                    {
                                        cb14.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId15.getText().toString()))
                                    {
                                        cb15.setChecked(true);
                                    }
                                    else if(itemId.equals(tvMaintenanceItemId16.getText().toString()))
                                    {
                                        cb16.setChecked(true);
                                    }
                                }

                            } catch (Exception e) {
                                String error = e.getMessage();
                            }

                        }
                    }
                case MSG_GET_MAINTENANCE_ITEM:
                    key = msg.getData().keySet().iterator().next();
                    if (BUNDLE_MSG_GET_MAINTENANCE_ITEM_FAIL.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, msg.getData().getString(BUNDLE_MSG_GET_MAINTENANCE_ITEM_FAIL), Toast.LENGTH_SHORT).show();
                    } else if (BUNDLE_LOCAL_ERROR.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, "服务器连接失败！", Toast.LENGTH_SHORT).show();

                    } else if (BUNDLE_MSG_GET_MAINTENANCE_ITEM_SUCCESS.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        String content = msg.getData().getString(BUNDLE_MSG_GET_MAINTENANCE_ITEM_SUCCESS);
                        if (!"".equals(content)) {
                            try {
                                com.alibaba.fastjson.JSONObject obj = com.alibaba.fastjson.JSONObject.parseObject(content);
                                JSONArray contentArray = obj.getJSONArray("content");
                                String maintenanceItemId = "";
                                String itemName = "";
                                String manHourFee = "";
                                String sparePartName = "";
                                String sparePartNumber = "";
                                String price = "";
                                for (int i = 0; i < contentArray.size(); i++) {
                                    // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                                    com.alibaba.fastjson.JSONObject job = contentArray.getJSONObject(i);
                                    maintenanceItemId = job.getString("maintenanceItemId");
                                    itemName = job.getString("itemName");
                                    manHourFee = job.getString("manHourFee");
                                    sparePartName = job.getString("sparePartName");
                                    sparePartNumber = job.getString("sparePartNumber");
                                    price = job.getString("price");
                                    switch (i) {
                                        case 0:
                                            tvMaintenanceItemId1.setText(maintenanceItemId);
                                            tvItemName1.setText(itemName);
                                            tvManHourFee1.setText(manHourFee);
                                            tvSpairPartName1.setText(sparePartName);
                                            tvSpairPartNumber1.setText(sparePartNumber);
                                            tvPrice1.setText(price);
                                            break;
                                        case 1:
                                            tvMaintenanceItemId2.setText(maintenanceItemId);
                                            tvItemName2.setText(itemName);
                                            tvManHourFee2.setText(manHourFee);
                                            tvSpairPartName2.setText(sparePartName);
                                            tvSpairPartNumber2.setText(sparePartNumber);
                                            tvPrice2.setText(price);
                                            break;
                                        case 2:
                                            tvMaintenanceItemId3.setText(maintenanceItemId);
                                            tvItemName3.setText(itemName);
                                            tvManHourFee3.setText(manHourFee);
                                            tvSpairPartName3.setText(sparePartName);
                                            tvSpairPartNumber3.setText(sparePartNumber);
                                            tvPrice3.setText(price);
                                            break;
                                        case 3:
                                            tvMaintenanceItemId4.setText(maintenanceItemId);
                                            tvItemName4.setText(itemName);
                                            tvManHourFee4.setText(manHourFee);
                                            tvSpairPartName4.setText(sparePartName);
                                            tvSpairPartNumber4.setText(sparePartNumber);
                                            tvPrice4.setText(price);
                                            break;
                                        case 4:
                                            tvMaintenanceItemId5.setText(maintenanceItemId);
                                            tvItemName5.setText(itemName);
                                            tvManHourFee5.setText(manHourFee);
                                            tvSpairPartName5.setText(sparePartName);
                                            tvSpairPartNumber5.setText(sparePartNumber);
                                            tvPrice5.setText(price);
                                            break;
                                        case 5:
                                            tvMaintenanceItemId6.setText(maintenanceItemId);
                                            tvItemName6.setText(itemName);
                                            tvManHourFee6.setText(manHourFee);
                                            tvSpairPartName6.setText(sparePartName);
                                            tvSpairPartNumber6.setText(sparePartNumber);
                                            tvPrice6.setText(price);
                                            break;
                                        case 6:
                                            tvMaintenanceItemId7.setText(maintenanceItemId);
                                            tvItemName7.setText(itemName);
                                            tvManHourFee7.setText(manHourFee);
                                            tvSpairPartName7.setText(sparePartName);
                                            tvSpairPartNumber7.setText(sparePartNumber);
                                            tvPrice7.setText(price);
                                            break;
                                        case 7:
                                            tvMaintenanceItemId8.setText(maintenanceItemId);
                                            tvItemName8.setText(itemName);
                                            tvManHourFee8.setText(manHourFee);
                                            tvSpairPartName8.setText(sparePartName);
                                            tvSpairPartNumber8.setText(sparePartNumber);
                                            tvPrice8.setText(price);
                                            break;
                                        case 8:
                                            tvMaintenanceItemId9.setText(maintenanceItemId);
                                            tvItemName9.setText(itemName);
                                            tvManHourFee9.setText(manHourFee);
                                            tvSpairPartName9.setText(sparePartName);
                                            tvSpairPartNumber9.setText(sparePartNumber);
                                            tvPrice9.setText(price);
                                            break;
                                        case 9:
                                            tvMaintenanceItemId10.setText(maintenanceItemId);
                                            tvItemName10.setText(itemName);
                                            tvManHourFee10.setText(manHourFee);
                                            tvSpairPartName10.setText(sparePartName);
                                            tvSpairPartNumber10.setText(sparePartNumber);
                                            tvPrice10.setText(price);
                                            break;
                                        case 10:
                                            tvMaintenanceItemId11.setText(maintenanceItemId);
                                            tvItemName11.setText(itemName);
                                            tvManHourFee11.setText(manHourFee);
                                            tvSpairPartName11.setText(sparePartName);
                                            tvSpairPartNumber11.setText(sparePartNumber);
                                            tvPrice11.setText(price);
                                            break;
                                        case 11:
                                            tvMaintenanceItemId12.setText(maintenanceItemId);
                                            tvItemName12.setText(itemName);
                                            tvManHourFee12.setText(manHourFee);
                                            tvSpairPartName12.setText(sparePartName);
                                            tvSpairPartNumber12.setText(sparePartNumber);
                                            tvPrice12.setText(price);
                                            break;
                                        case 12:
                                            tvMaintenanceItemId13.setText(maintenanceItemId);
                                            tvItemName13.setText(itemName);
                                            tvManHourFee13.setText(manHourFee);
                                            tvSpairPartName13.setText(sparePartName);
                                            tvSpairPartNumber13.setText(sparePartNumber);
                                            tvPrice13.setText(price);
                                            break;
                                        case 13:
                                            tvMaintenanceItemId14.setText(maintenanceItemId);
                                            tvItemName14.setText(itemName);
                                            tvManHourFee14.setText(manHourFee);
                                            tvSpairPartName14.setText(sparePartName);
                                            tvSpairPartNumber14.setText(sparePartNumber);
                                            tvPrice14.setText(price);
                                            break;
                                        case 14:
                                            tvMaintenanceItemId15.setText(maintenanceItemId);
                                            tvItemName15.setText(itemName);
                                            tvManHourFee15.setText(manHourFee);
                                            tvSpairPartName15.setText(sparePartName);
                                            tvSpairPartNumber15.setText(sparePartNumber);
                                            tvPrice15.setText(price);
                                            break;
                                        case 15:
                                            tvMaintenanceItemId16.setText(maintenanceItemId);
                                            tvItemName16.setText(itemName);
                                            tvManHourFee16.setText(manHourFee);
                                            tvSpairPartName16.setText(sparePartName);
                                            tvSpairPartNumber16.setText(sparePartNumber);
                                            tvPrice16.setText(price);
                                            break;


                                    }
                                }
                            } catch (Exception e) {
                                String error = e.getMessage();
                            }
                        }
                        getWorkOrderItem(carInfoId);
                    }
                    break;
                case MSG_SUBMIT_MAINTENANCE_ITEM:
                    key = msg.getData().keySet().iterator().next();
                    if (BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_FAIL.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, msg.getData().getString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_FAIL), Toast.LENGTH_SHORT).show();
                    } else if (BUNDLE_LOCAL_ERROR.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, "服务器连接失败！", Toast.LENGTH_SHORT).show();

                    } else if (BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_CHOOSE.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, msg.getData().getString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_CHOOSE), Toast.LENGTH_SHORT).show();

                    } else if (BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_SUCCESS.equals(key)) {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                        Toast.makeText(UpdateWorkOrderActivity.this, msg.getData().getString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_SUCCESS), Toast.LENGTH_SHORT).show();
                        Intent   intent = new Intent(UpdateWorkOrderActivity.this,
                                DispWorkOrderActivity.class);
                        intent.putExtra("carInfoId", carInfoId);
                        startActivity(intent);
                    }

                    break;
                default:
                    break;
            }
            removeMessages(msg.what);
        }
    };

    protected void submitMaintenanceItem(String workOrderContent) {

        if (Utils.isNetworkAvailable(UpdateWorkOrderActivity.this) == false) {
            Toast.makeText(UpdateWorkOrderActivity.this, "网络尚未连接，请连接网络！", Toast.LENGTH_SHORT).show();
            return;
        }

        final String[] key = {"workOrderContent"};
        final String[] value = {workOrderContent};
        progressDialog = ProgressDialog.show(UpdateWorkOrderActivity.this,
                getResources().getString(R.string.notice), "正在修改工单...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bundle bundle = new Bundle();
                try {
                    String rs = WSClient.soapGetInfo("updateWorkOrder", key, value);
                    JSONTokener jsonTokener = new JSONTokener(rs);
                    JSONObject jsonObject = (JSONObject) jsonTokener
                            .nextValue();
                    String status = jsonObject.getString("status");
                    String content = jsonObject.get("content").toString();
                    if ("1".equals(status)) {

                        bundle.putString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_SUCCESS, "修改工单成功！");
                    } else if ("2".equals(status)) {

                        bundle.putString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_CHOOSE, "请选择养护项目！");
                    } else {
                        bundle.putString(BUNDLE_MSG_SUBMIT_MAINTENANCE_ITEM_FAIL, "修改工单失败，请重试！");
                    }
                } catch (Exception e) {

                    bundle.putString(BUNDLE_LOCAL_ERROR, "访问服务器失败！");
                }
                Message msg = myHandler.obtainMessage();
                msg.what = MSG_SUBMIT_MAINTENANCE_ITEM;
                msg.setData(bundle);
                myHandler.sendMessage(msg);
            }
        }).start();
    }

    protected void getMaintenanceItem(String repairShopId) {

        if (Utils.isNetworkAvailable(UpdateWorkOrderActivity.this) == false) {
            Toast.makeText(UpdateWorkOrderActivity.this, "网络尚未连接，请连接网络！", Toast.LENGTH_SHORT).show();
            return;
        }

        final String[] key = {"repairShopId"};
        final String[] value = {repairShopId};
        progressDialog = ProgressDialog.show(UpdateWorkOrderActivity.this,
                getResources().getString(R.string.notice), "正在加载保养项目...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bundle bundle = new Bundle();
                try {
                    String rs = WSClient.soapGetInfo("getMaintenanceItemByRepairShopId", key, value);
                    JSONTokener jsonTokener = new JSONTokener(rs);
                    JSONObject jsonObject = (JSONObject) jsonTokener
                            .nextValue();
                    String status = jsonObject.getString("status");
                    String content = jsonObject.get("content").toString();
                    if ("1".equals(status)) {

                        bundle.putString(BUNDLE_MSG_GET_MAINTENANCE_ITEM_SUCCESS, rs);
                    } else {
                        bundle.putString(BUNDLE_MSG_GET_MAINTENANCE_ITEM_FAIL, "保养项目加载失败，请重试！");
                    }
                } catch (Exception e) {

                    bundle.putString(BUNDLE_LOCAL_ERROR, "访问服务器失败！");
                }
                Message msg = myHandler.obtainMessage();
                msg.what = MSG_GET_MAINTENANCE_ITEM;
                msg.setData(bundle);
                myHandler.sendMessage(msg);
            }
        }).start();
    }

    protected void getWorkOrderItem(String carInfoId) {

        if (Utils.isNetworkAvailable(UpdateWorkOrderActivity.this) == false) {
            Toast.makeText(UpdateWorkOrderActivity.this, "网络尚未连接，请连接网络！", Toast.LENGTH_SHORT).show();
            return;
        }

        final String[] key = {"carInfoId"};
        final String[] value = {carInfoId};
        progressDialog = ProgressDialog.show(UpdateWorkOrderActivity.this,
                getResources().getString(R.string.notice), "正在加载工单项目...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bundle bundle = new Bundle();
                try {
                    String rs = WSClient.soapGetInfo("getWorkOrderItem", key, value);
                    JSONTokener jsonTokener = new JSONTokener(rs);
                    JSONObject jsonObject = (JSONObject) jsonTokener
                            .nextValue();
                    String status = jsonObject.getString("status");
                    String content = jsonObject.get("content").toString();
                    if ("1".equals(status)) {

                        bundle.putString(BUNDLE_MSG_GET_WORK_ORDER_ITEM_SUCCESS, rs);
                    } else {
                        bundle.putString(BUNDLE_MSG_GET_WORK_ORDER_ITEM_FAIL, "工单项目加载失败，请重试！");
                    }
                } catch (Exception e) {

                    bundle.putString(BUNDLE_LOCAL_ERROR, "访问服务器失败！");
                }
                Message msg = myHandler.obtainMessage();
                msg.what = MSG_GET_WORK_ORDER_ITEM;
                msg.setData(bundle);
                myHandler.sendMessage(msg);
            }
        }).start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getAppManager().finishActivity(this);
    }
}